<?php
/**
 * 组成表名
 * @author qishunweb
 *
 */
class TableConfig {
 	public $table=array 	(
		'admin' => array(
	 		'name'  => 'admin',
	 		// 缓存索引键，有索引键的表，添加、删除、修改的速度稍慢，对单条读取速度快，
	 		'index' => array('name','id'),
	 		'field' => array('name','password','fund_user_id','eo_admin_group','dept_id','employee_id','status','teacher_id','admin_type','default_language')
	    ),
 		'function'  => array(
 			'name'  => 'function',
 			'index' => array('id'),
 			'field' => array('mark','controller','function','father_id','display')
 		),
 		'admin_group' => array(
	 		'name'  => 'admin_group',
 			'index' => array('id'),
 			'field' =>  array('name','permissions_functoin','admin','code')
 		),
 		'user' =>array(
 			'name'	=> 'user',
 			'index'	=> array('id'),
 			'field' => array('id','english_name','password','phone','email','user_id','qq','skype_id','real_phone','integral','province','city','sex','address','zipcode','lead_source','status','register_time','fav_content','content','employee_id','user_class','user_experience_class','user_monthly_class','class_period_validity','monthly_class_period_validity','job','level','level_number','user_moeny','sms_server','default_communication','portrait','big_portrait','user_type','sms_code','fund_user_id','openid','nickname','register_type','user_kind','qq_bind_status','qq_bind_id')
 		),
 		'letter_station' => array(
 			'name'  => 'letter_station',
 			'index' => array('id'),
 			'field' => array('content','title','sender','time','user_id','status')
 		),
 		'admin_operation_log' => array(
 			'name'  => 'admin_operation_log',
 			'index' => array(),
 			'field' => array('controller','function','time','admin_id','admin_group_id','admin_name','operation')
 		),
 		'news' =>array(
 			'name' => 'news',
 			'index'=> array(),
 			'field' => array('title','key_title','key_content','news_source','pic','detail_pic','video','content','smalltext','news_class_id','recom_status','pub_status','time','type','nav_id')
 		),
 		'admin_login_log' =>array(
 			'name' => 'admin_login_log',
 			'index'=> array(),
 			'field' => array('login_time','name','admin_id')
 		),
 		'user_login_log' => array(
 			'name' => 'user_login_log',
 			'index' => array(),
 			'field' => array('ip','login_time','english_name','user_id')
 		),
 		'region' => array(
 			'name' => 'region',
 			'index' => array(),
 			'field' => array()
 		),
 		'send_info_template' => array(
 			'name' => 'send_info_template',
 			'index' => array(),
 			'field' => array('title','content','type')
 		),
 		'email_sendlist' => array(
 			'name' => 'email_sendlist',
 			'index'=> array(),
 			'field'=>array('email','title','content','time','status')
 		),
 		'mobile_sendlist' => array(
 			'name' => 'mobile_sendlist',
 			'index'=> array(),
 			'field'=>array('phone','content','time','target_id','status')
 		),
 		'employees' => array(
 			'name' => 'employees',
 			'index'=> array(),
 			'field'=>array('name','entry_time','add_time','identity_number','position','type','status','department','phone','mobile_phone','address','email','nationality')
 		),
	 	'nav' => array(
 			'name' => 'nav',
 			'index'=> array(),
 			'field'=>array('id','title','url','father_id','sort','banner','status','news_type','news_status','link_type')
	 	),
 		'teacher' => array(
 			'name'  => 'teacher',
 			'index' => array(),
 			'field' => array('id','english_level','teach_level','skype','qq','skype_status','qq_status','introduce','name','phone','address','email','nationality','add_time','status','serial_number','age','resume','english_resume','contract_category','job_start_date','job_end_date','employees_id','good_course','sex','portrait','list_portrait','detail_portrait','experience','hobby','introduce_chinese','introduce_english','word_mouth','real_education_experience','education_experience','teaching_style','base_integral','pxh','network_stat')
 		),
 		'finance' => array(
 			'name'  => 'finance',
 			'index' => array(),
 			'field' => array('integral','currency_type','bank_account','bank','teacher_id')
 		),
 		'bank' => array(
 			'name'=>'bank',
 			'index' => array(),
 			'field' => array()
 		),
 		'course' => array(
 			'name' => 'course',
 			'index' => array(),
 			'field' => array('id','theme','type','overview','serial_number','class_hour','level','status','homemade_time','homemade_producer','book_barcode','book_press','book_version','book_time','book_chapter_number','status','describe','teaching_material','english_type','source','dept_id','big_course_type','course_img','course_url','for_purpose_people','for_purpose_study','course_recommend')
 		),
 		'teacher_class' =>array(
 			'name'  => 'teacher_class',
 			'index' => array(),
 			'field' => array('teacher_id','date','time','status','confirm_status')
 		),
	 	'evaluation' => array(
	 		'name' => 'evaluation',
	 		'index' => array(),
	 		'field' => array('user_id','book_course_id','satisfication','call','pronuncia','method','time','user_id','evaluation')
	 	),
 		'book_course' => array(
 			'name'  =>'book_course',
 			'index' => array(),
 			'field' => array('id','book_no','book_type','class_status','pay_status','pay_userclass','course_needclass','user_id','teacher_id','teacher_class_id','course_type','course_id','chapter_id','chapter_no','chapter_name','message','book_date','book_time','communication_tools','teacher_status','add_time','add_user','confirm_admin','confirm_time','complete_admin','complete_time','cancel_admin','cancel_time','user_status','book_course','qq','skype_id','phone','english_name','teaching_material','original_teacher_id','substitute','report_status','sms_notify')
 		),
 		'online_question' => array(
 			'name'  =>'online_question',
 			'index' => array(),
 			'field' => array('add_time','user_id','question','answer','admin_id','answer_time')
 		),//投诉
 		'complaint' =>array(
 			'name'  =>'complaint',
 			'index' => array(),
 			'field' => array('target_id','order_type','add_time','type','content','user_id','status','follow_employee_id','follow_content','employee_id','dept_id')
 		),
 		'collection' =>array(
 			'name'  =>'collection',
 			'index' => array(),
 			'field' => array('user_id','teacher_id','add_time')
 		),
 		'chapter' =>array(
 			'name'  =>'chapter',
 			'index' => array(),
 			'field' => array('id','name','course_id','chater_no','status','document','content','add_time','english_name','english_content')
 		),
 		'book_course_log' => array(
 			'name' => 'book_course_log',
 			'index' => array(),
 			'field' => array('book_course_id','type','add_time','remark','add_admin')
 		),
 		'user_class_hour_log' => array(
 			'name'  => 'user_class_hour_log',
 			'index' => array(),
 			'field' => array('type','target_id','add_time','add_user','class_hour','user_id','class_type','remark')
 		),
	 	'course_record' => array(
 			'name'  => 'course_record',
 			'index' => array(),
 			'field' => array('book_course_id','content','status','add_time','teacher_id','user_id','score','feedback','grammar','vocabulary','pronunciation','teacher_message')
	 	),
	 	'product' => array(
 			'name'  => 'product',
 			'index' => array(),
 			'field' => array('id','name','lesson','period_validity','price','type','add_time','status','serial_number','discount','return_ticket','unit','unit_price','new_user_favour','active_type','target_course')
	 	),
 		'level' => array(
 			'name' => 'level',
 			'index' => array(),
 			'field' => array('level','subject','content','cycle','english_describe','english_subject','target')
 		),
	 	'teacher_evaluation' => array(
 			'name' => 'teacher_evaluation',
 			'index' => array(),
 			'field' => array('call_effect','satisfied','pronunciation','method','evaluation','user_id','teacher_id','book_course_id')
	 	),
	 	'user_leave' => array(
 			'name' => 'user_leave',
 			'index' => array(),
 			'field' => array('date','add_time','few_days','user_id','status')
	 	),
	 	'ticket' => array(
 			'name' => 'ticket',
 			'index' => array(),
 			'field' => array('id','receive_user_id','number','password','add_time','add_admin','activation_time','activation_admin','valid_start_time','valid_end_time','status','product_id','verifier')
	 	),
	 	'ticket_log' => array(
 			'name' => 'ticket_log',
 			'index' => array(),
 			'field' => array('send_time','send_admin','ticket_id','add_time','add_admin','use_user','use_user_id','use_time','activation_time','activation_admin','cancellation_time','cancellation_admin','order_id')
	 	),
 		'order' => array(
 			'name' => 'order',
 			'index' => array(),
 			'field' => array('id','order_type','order_status','order_no','user_id','ticket_id','order_amount','user_money','online_money','discount_money','ticket_money','pay_time','pay_status','pay_type','product_id','add_user','add_time','confirm_admin','confirm_time','complete_time','complete_user','cancel_user','cancel_time','order_give_point','comment_give_point','teacher_give_point','student_give_point','transaction_no','monthly_start_date')
 		),
 		'sys_config' => array(
 			'name' => 'sys_config',
 			'index' => array(),
 			'field' => array('id','sys_key','sys_value')
 		),
	 	'order_log' => array(
 			'name' => 'order_log',
 			'index' => array(),
 			'field' => array('order_id','type','add_time','add_admin','remark')
	 	),
	 	'pay_log' => array(
 			'name' => 'pay_log',
 			'index' => array('id','target_id','target_sn'),
 			'field' => array('target_id','user_id','target_sn','amount','pay_type','type','add_time','add_user','confirmed_time','confirmed_admin','status')
	 	),
	 	'teacher_log' => array(
 			'name' => 'teacher_log',
 			'index' => array(),
 			'field' => array('target_id','add_time','add_admin','type','teacher_id','integral','money','remark')
	 	),
 		'news_class' => array(
 			'name' => 'news_class',
 			'index' => array(),
 			'field' => array('title','father_id')
 		),
 		'user_money_log' => array(
 			'name' => 'user_money_log',
 			'index' => array(),
 			'field' => array('type','money','time','add_user','user_id','content')
 		),//学习目的
	 	'purpose' => array(
 			'name' => 'purpose',
 			'index' => array(),
 			'field' => array('title','father_id')
		),
 		'course_type' => array(
 			'name' => 'course_type',
 			'index' => array(),
 			'field' => array('english_title','pic','smalltext','content','type','status','course_type')
 		),
 		'user_overdue_empty' => array(
 			'name' => 'user_overdue_empty',
 			'index' => array(),
 			'field' => array('user_id','class','type','period_validity','time')
 		),
 		'user_invite_code' => array(
 			'name' =>'user_invite_code',
 			'index' =>array(),
 			'field' => array()
 		),
 		'message' => array(
 			'name' =>'message',
 			'index' =>array(),
 			'field' => array('title','content','add_time','user_id','name')
 		),
 		'instant_texting_log' => array(
 			'name' =>'instant_texting_log',
 			'index' =>array(),
 			'field' => array('phone','content','time','status','number')
 		),
 		'book_course_evaluation' => array(
 			'name' =>'book_course_evaluation',
 			'index' =>array(),
 			'field' => array('book_course_id','satisfaction','call','pronuncia','method','time','user_id','evaluation')
 		),
 		'user_integral_log' => array(
 			'name' =>'user_integral_log',
 			'index' =>array(),
 			'field' => array('time','integral','add_user','type','user_id')
 		),
 		'wage' => array(
 			'name' =>'wage',
 			'index' =>array(),
 			'field' => array('teacher_id','money','time','type')
 		),
 		'sys_teacher_salary' => array(
 			'name' =>'sys_teacher_salary',
 			'index' =>array(),
 			'field' => array('key','type','start_time','end_time','star','per_salary','status','integral')
 		),
 		'sale_purpose' => array(
 			'name' =>'sale_purpose',
 			'index' =>array(),
 			'field' => array('id','year','month','sale_purpose','register_purpose','register_pay_purpose','add_user','add_time')
 		), 		
 		'fund_user' => array(
 			'name' =>'fund_user',
 			'index' =>array(),
 			'field' => array('id','name','phone','email','fund_user_id','qq','skype_id','integral','serial_number','fund_user_rank','sex','province','city','district','address','zipcode','status','employee_id','fav_content','content','job','add_time','add_user')
 		) 		
	);
	public function  name ($tableName)	{
		$this->dbName = $GLOBALS['db_name'];
		$this->tablePrefix = $GLOBALS['table_prefix'];
		if (empty($this->table[$tableName])){
			exit('table does not exists'.$tableName);
		}
		else{
			return   $this->dbName.".`".$this->tablePrefix.$this->table[$tableName]['name']."`"	;	
		}
	}
	/**
	 * 是否存在这个索引
	 * @param unknown $k
	 */
	public function inIndex($tableName,$k){
		return  in_array($k,$this->table[$tableName]['index']);
	}
	
	/**  给字段赋值
	 */
	public function getFieldValue($table,$data){
		$column = array();
		foreach ($this->table[$table]['field'] as $v){
			if (isset($data[$v])){
				$column[$v] = $data[$v];
			}
		}
		return $column;
	}
	/**  获取所有的字段
	 */
	public function getFieldArray($table){
		$column_list = array();
		if(!empty($this->table[$table]['field'])){
			$column_list = $this->table[$table]['field'];
		}
		return $column_list;
	}
}
?>